Skip to content

fix: use Docker Compose secrets for LLM keys (#160) - #168

Merged
azchin merged 4 commits into
ossf:mainfrom
tusharshah21:fix/docker-secrets-llm-keys
May 9, 2026
Merged

azchin merged 4 commits into
ossf:mainfrom
tusharshah21:fix/docker-secrets-llm-keys

Conversation

@tusharshah21

@tusharshah21 tusharshah21 commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

fix: use Docker Compose secrets for LLM keys

Summary

Replace environment variable delivery of LITELLM_MASTER_KEY, POSTGRES_PASSWORD, and per-CRS OSS_CRS_LLM_API_KEY with Docker Compose file-based secrets per the Docker Compose secrets best practice
(https://docs.docker.com/compose/how-tos/use-secrets/).

Previously, sensitive LLM keys were injected as plaintext environment variables into containers. They are now delivered as Docker secrets mounted at /run/secrets/, preventing accidental exposure via docker inspect, logs, or child process env inheritance.

User Impact

  • User-facing change

CRS authors who read OSS_CRS_LLM_API_KEY directly from the environment
must update to read from the file path provided by OSS_CRS_LLM_API_KEY_FILE:
Closes #160

# Before
api_key = os.environ["OSS_CRS_LLM_API_KEY"]

# After
with open(os.environ["OSS_CRS_LLM_API_KEY_FILE"]) as f:
    api_key = f.read().strip()
    

@azchin

azchin commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR! I'll take a proper look over the weekend, in the meanwhile could you sign your commits (https://github.com/ossf/oss-crs/blob/main/CONTRIBUTING.md#developer-certificate-of-origin-dco) and force push?

We also updated main with a major internal refactor, hence the conflicts.

@tusharshah21
tusharshah21 force-pushed the fix/docker-secrets-llm-keys branch from fa1c941 to 4dfd9a8 Compare April 16, 2026 11:48
@tusharshah21

Copy link
Copy Markdown
Contributor Author

Done mate, covered the conflicts too

@tusharshah21

Copy link
Copy Markdown
Contributor Author

any updates?

@azchin azchin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing missing is converting LiteLLM config environment variables into secrets.

The flow is OSS-CRS picks up environment variables from the host according to litellm-config.yaml, and exposes them as env vars for the guest LiteLLM proxy Docker containers. See below for details.

Comment thread oss-crs-infra/litellm-key-gen/main.py Resolved
environment:
- LITELLM_MASTER_KEY={{ llm_context.litellm_master_key }}
- DATABASE_URL=postgresql://{{ postgres_user }}:{{ llm_context.postgres_password }}@{{ postgres_host }}:{{ postgres_port }}/{{ postgres_user }}
{%- for key, value in llm_context.litellm_env.items() %}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these need to be converted to secrets as well. This is where the user can provide e.g. OPENAI_API_KEY, and their LiteLLM-defined config picks it up via os.environ/OPENAI_API_KEY

What we should do here is create a wrapper script that somehow enumerates all the secret files we need (maybe convey it through a JSON or some other KVP encoding) and set the environment vars for the main LiteLLM process. Similar to how you already do export ... && exec litellm but for an arbitrary number of {environment variables : secret file}.

Unfortunately LiteLLM only supports env vars for keys in their proxy, they don't support secret files. https://docs.litellm.ai/docs/proxy/configs

The following is an example, with EXTERNAL_LITELLM_API_KEY.

api_base: os.environ/EXTERNAL_LITELLM_API_BASE

@azchin

azchin commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Also since OSS_CRS_LLM_API_KEY --> OSS_CRS_LLM_API_KEY_FILE is a breaking change, I will need to update all of the existing CRSs in the registry.

@tusharshah21

Copy link
Copy Markdown
Contributor Author

my bad for the delays reporting back in a while

Tushar Kumar and others added 2 commits May 4, 2026 10:29
Signed-off-by: tusharshah21 <tusharkumarshah14394@gmail.com>
Signed-off-by: tusharshah21 <tusharkumarshah14394@gmail.com>
@tusharshah21
tusharshah21 force-pushed the fix/docker-secrets-llm-keys branch from 70ceb4b to 1a6bfc8 Compare May 4, 2026 05:00
@tusharshah21

Copy link
Copy Markdown
Contributor Author

check now mate!

@azchin

azchin commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Looks great! Can you resolve the CI errors? uv run verify should tell you what's wrong locally.

Please also apply this diff, I updated crs-codex.yaml on main to match your updates.

diff --git a/registry/crs-codex.yaml b/registry/crs-codex.yaml
index 7c542ea..622174b 100644
--- a/registry/crs-codex.yaml
+++ b/registry/crs-codex.yaml
@@ -3,4 +3,4 @@ type:
   - bug-fixing
 source:
   url: https://github.com/Team-Atlanta/crs-codex.git
-  ref: refactor/sidecar
+  ref: main

@azchin
azchin merged commit 9f7bf28 into ossf:main May 9, 2026
7 checks passed
@azchin

azchin commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: use secrets in Docker compose instead of environment variables

2 participants